\documentclass[twoside,titlepage]{report}

\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{wrapfig}
\usepackage{amsmath}
\usepackage{moreverb}


\title{MatPix: A Matrix Based Scientific Language with GPU Computation}

\author{
\begin{tabular}{cccc}
David Burkat & Oliver Cossairt & Robert Hawkins & Ben London\\
dsb2117@columbia.edu &
ollie@cs.columbia.edu &
rh2305@columbia.edu &
bal2123@columbia.edu\\
\end{tabular}
}
\begin{document}


\maketitle
\pagenumbering{Roman}
\tableofcontents

\chapter{Introduction}
\input{wp.tex}
\pagenumbering{arabic}
\setcounter{page}{1}


   
\chapter{Tutorial}
\input{tutorial.tex}
\chapter{Language Reference Manual}
\input{lrm.tex}
\chapter{Project Plan}
\input{pp.tex}

\chapter{Architecture Design}
\input{ad.tex}
\chapter{Testing Plan}
\input{tp.tex}

\chapter{Lessons Learned}
\input{ll.tex}
\chapter{Future Work}
\input{future.tex}

\begin{onecolumn}
\begin{scriptsize}
\begin{thebibliography}{00}
\bibitem{matlab}
Matlab, http://www.mathworks.com/


\end{thebibliography}
\end{scriptsize}
\end{onecolumn}

\appendix
\chapter{Syntax Overview}
Here we give a succinct overview of the syntax of MatPix for user reference.
\section{Lexer Grammar}
\begin{verbatimtab}
PLUS   : `+' ;
MINUS  : `-' ;
MUL    : ".*";
DIV    : "./";
MOD	   : `%' ;
ASSIGN : `=' ;
SEMI   : `;' ; 
DOTPROD: `*' ;
COMMA  : ',' ;
COLON  : `:' ;
POUND  : `#' ;

LBRACKET : `[' ;
RBRACKET : `]' ;
LSCOPE : `{' ;
RSCOPE : `}' ;
ROWSEP : `|' ;

NOT : `!';
AND : "&&";
OR : "||";
LOGGT : `>';
LOGLT : `<';
LOGGTE : ">=";
LOGLTE : "<=";
LOGEQ : "==";
LOGNEQ : "!=";
LPAREN : "(" ;
RPAREN : ")" ;
INC : "++";
DEC : "--";
TRANS : "'";

LETTER : ( `a'..`z' | `A'..`Z' ) ;
DIG : `0'..`9' ;
INT : (DIG)+ ;
NUMBER : INT (`.' INT)? | `.' INT;

EXPON : (`e' | `E') (MINUS)? INT ;
FLOAT : NUMBER (EXPON)?				;

SL_COMMENT : "//" (~`\n')*; 
ML_COMMENT : "/*" .* "*/"; 

ID : LETTER (LETTER | DIG | `_')* ;

SCALAR : (MINUS FLOAT) | FLOAT ;

STRING :  `"' ( `"' `"' | ~(`"'))*  `"'; 

WS  :   ( ` ' | `\t' | `\n' | `\r' );
\end{verbatimtab}

\section{Parser Grammar}
\begin{verbatimtab}
program : (stmt)+ EOF;
constant : SCALAR	| constmatrix | STRING ;
arraySlice : LBRACKET rangeList RBRACKET;
rangeList : range COMMA range;
range : (expr (COLON expr (COLON  expr )?)?) | COLON ;
constmatrix : LBRACKET (row)+ RBRACKET;
row : cols (ROWSEP)?;
cols : SCALAR (COMMA SCALAR)*;
matrixdecl : "matrix" ID (LBRACKET expr COMMA expr RBRACKET)?;
stmt : expr SEMI | functionDefinition SEMI | controlflow | "return" expr SEMI | 
	SEMI | LSCOPE (stmt)+ RSCOPE;
expr : matrixdecl (ASSIGN logicExpr)? | logicExpr (ASSIGN logicExpr)?;
logicExpr : predExpr ((AND | OR) logicExpr)?; 
predExpr : ((NOT)? addExpr) ((LOGGT|LOGLT|LOGGTE|LOGLTE|LOGEQ|LOGNEQ) predExpr)?;
addExpr : mulExpr ( (PLUS | MINUS) mulExpr )*; 
mulExpr : signExpr ( (MUL | DIV | MOD | DOTPROD) signExpr )*;
signExpr : (MINUS)? incExpr ;
incExpr : atom (INC | DEC | TRANS)?;
atom : identifier ( arraySlice | argList)? | constant | LPAREN expr RPAREN;
identifier : ID ;
functionDefinition :  "function" ID defArgList LSCOPE newScope RSCOPE; 
newScope : (stmt)*;
defArgList : LPAREN (ID (COMMA ID)* )? RPAREN;
argList : LPAREN (expr (COMMA expr)* )? RPAREN; 
controlflow : (ifstmt | whilestmt | forstmt);
predicate: logicExpr;
ifstmt : "if" LPAREN predicate RPAREN LSCOPE newScope RSCOPE 
	("else" LSCOPE newScope RSCOPE )?;  
whilestmt : "while" LPAREN predicate RPAREN LSCOPE newScope  RSCOPE;        
forstmt: "for" LPAREN ID ASSIGN range RPAREN LSCOPE newScope RSCOPE;
\end{verbatimtab}

\chapter{Code Repository}
Here we present a complete listing of all source code and testing code for our language.

\newcommand{\loadsrc}[2]{
\subsection{#1}
{\scriptsize{
\verbatimtabinput[8]{#2}}}
}

\section{Parser}
\loadsrc{MPLexParseWalk.g}{../LRM/src/MPLexParseWalk.g}
\loadsrc{Main.java}{../LRM/src/Main.java}

\clearpage
\section{Compiler}
\loadsrc{MPSymbolTable.java}{../LRM/src/MPSymbolTable.java}
\loadsrc{MPExpression.java}{../LRM/src/MPExpression.java}
\loadsrc{MPException.java}{../LRM/src/MPException.java}

\clearpage
\section{GPU Backend}
\loadsrc{matpix.hpp}{../LRM/MatPix/matpix.hpp}
\loadsrc{matrix.hpp}{../LRM/MatPix/matrix.hpp}
\loadsrc{PBuffer.cpp}{../LRM/MatPix/PBuffer.cpp}
\loadsrc{PBuffer.h}{../LRM/MatPix/PBuffer.h}
\loadsrc{util.cpp}{../LRM/MatPix/util.cpp}
\loadsrc{util.hpp}{../LRM/MatPix/util.hpp}

\clearpage
\section{Testing Configuration}
\loadsrc{Makefile}{../LRM/tests/Makefile}
\loadsrc{run.py}{../LRM/tests/bin/run.py}


\clearpage
\section{Testing Scripts}
\subsection{Successful Tests}
\loadsrc{arithmetic.mpx}{../LRM/tests/mpx/arithmetic.mpx}
\loadsrc{arithmetic.cpp}{../LRM/tests/cpp/arithmetic.cpp}
\loadsrc{arithmetic.log}{../LRM/tests/bin/pass/arithmetic.log}

\loadsrc{constmatrix.mpx}{../LRM/tests/mpx/constmatrix.mpx}
\loadsrc{constmatrix.cpp}{../LRM/tests/cpp/constmatrix.cpp}
\loadsrc{constmatrix.log}{../LRM/tests/bin/pass/constmatrix.log}

\loadsrc{ctrlFlow.mpx}{../LRM/tests/mpx/ctrlFlow.mpx}
\loadsrc{ctrlFlow.cpp}{../LRM/tests/cpp/ctrlFlow.cpp}
\loadsrc{ctrlFlow.log}{../LRM/tests/bin/pass/ctrlFlow.log}

\loadsrc{dotprod.mpx}{../LRM/tests/mpx/dotprod.mpx}
\loadsrc{dotprod.cpp}{../LRM/tests/cpp/dotprod.cpp}
\loadsrc{dotprod.log}{../LRM/tests/bin/pass/dotprod.log}

\loadsrc{functiondef.mpx}{../LRM/tests/mpx/functiondef.mpx}
\loadsrc{functiondef.cpp}{../LRM/tests/cpp/functiondef.cpp}
\loadsrc{functiondef.log}{../LRM/tests/bin/pass/functiondef.log}

\loadsrc{gauss\_jordan.mpx}{../LRM/tests/mpx/gauss_jordan.mpx}
\loadsrc{gauss\_jordan.cpp}{../LRM/tests/cpp/gauss_jordan.cpp}
\loadsrc{gauss\_jordan.log}{../LRM/tests/bin/pass/gauss_jordan.log}

\loadsrc{logictest.mpx}{../LRM/tests/mpx/logictest.mpx}
\loadsrc{logictest.cpp}{../LRM/tests/cpp/logictest.cpp}
\loadsrc{logictest.log}{../LRM/tests/bin/pass/logictest.log}

\loadsrc{recursive.mpx}{../LRM/tests/mpx/recursive.mpx}
\loadsrc{recursive.cpp}{../LRM/tests/cpp/recursive.cpp}
\loadsrc{recursive.log}{../LRM/tests/bin/pass/recursive.log}

\loadsrc{regression.mpx}{../LRM/tests/mpx/regression.mpx}
\loadsrc{regression.cpp}{../LRM/tests/cpp/regression.cpp}
\loadsrc{regression.log}{../LRM/tests/bin/pass/regression.log}

\loadsrc{sliceAssign.mpx}{../LRM/tests/mpx/sliceAssign.mpx}
\loadsrc{sliceAssign.cpp}{../LRM/tests/cpp/sliceAssign.cpp}
\loadsrc{sliceAssign.log}{../LRM/tests/bin/pass/sliceAssign.log}

\loadsrc{sum.mpx}{../LRM/tests/mpx/sum.mpx}
\loadsrc{sum.cpp}{../LRM/tests/cpp/sum.cpp}
\loadsrc{sum.log}{../LRM/tests/bin/pass/sum.log}

\loadsrc{transpose.mpx}{../LRM/tests/mpx/transpose.mpx}
\loadsrc{transpose.cpp}{../LRM/tests/cpp/transpose.cpp}
\loadsrc{transpose.log}{../LRM/tests/bin/pass/transpose.log}

\section{Compiler Error Tests}

\loadsrc{lvalue\_fail\_m.mpx}{../LRM/tests/mpx/lvalue_fail_m.mpx}
\loadsrc{lvalue\_fail\_m.log}{../LRM/tests/bin/pass/lvalue_fail_m.log}

\loadsrc{scope\_if\_fail\_m.mpx}{../LRM/tests/mpx/scope_if_fail_m.mpx}
\loadsrc{scope\_if\_fail\_m.log}{../LRM/tests/bin/pass/scope_if_fail_m.log}

\loadsrc{scope\_func1\_fail\_m.mpx}{../LRM/tests/mpx/scope_func1_fail_m.mpx}
\loadsrc{scope\_func1\_fail\_m.log}{../LRM/tests/bin/pass/scope_func1_fail_m.log}

\loadsrc{scope\_func2\_fail\_m.mpx}{../LRM/tests/mpx/scope_func2_fail_m.mpx}
\loadsrc{scope\_func2\_fail\_m.log}{../LRM/tests/bin/pass/scope_func2_fail_m.log}

\loadsrc{funcCall\_notDef\_fail\_m.mpx}{../LRM/tests/mpx/funcCall_notDef_fail_m.mpx}
\loadsrc{funcCall\_notDef\_fail\_m.log}{../LRM/tests/bin/pass/funcCall_notDef_fail_m.log}

\loadsrc{funcDef\_dup\_fail\_m.mpx}{../LRM/tests/mpx/funcDef_dup_fail_m.mpx}
\loadsrc{funcDef\_dup\_fail\_m.log}{../LRM/tests/bin/pass/funcDef_dup_fail_m.log}

\loadsrc{syntax\_fail\_m.mpx}{../LRM/tests/mpx/syntax_fail_m.mpx}
\loadsrc{syntax\_fail\_m.log}{../LRM/tests/bin/pass/syntax_fail_m.log}

\loadsrc{matIndex\_fail\_m.mpx}{../LRM/tests/mpx/matIndex_fail_m.mpx}
\loadsrc{matIndex\_fail\_m.log}{../LRM/tests/bin/pass/matIndex_fail_m.log}

\section{Runtime Error Tests}

\loadsrc{badDim\_add\_fail\_r.mpx}{../LRM/tests/mpx/badDim_add_fail_r.mpx}
\loadsrc{badDim\_add\_fail\_r.cpp}{../LRM/tests/cpp/badDim_add_fail_r.cpp}
\loadsrc{badDim\_add\_fail\_r.log}{../LRM/tests/bin/pass/badDim_add_fail_r.log}

\loadsrc{badDim\_dotprod\_fail\_r.mpx}{../LRM/tests/mpx/badDim_dotprod_fail_r.mpx}
\loadsrc{badDim\_dotprod\_fail\_r.cpp}{../LRM/tests/cpp/badDim_dotprod_fail_r.cpp}
\loadsrc{badDim\_dotprod\_fail\_r.log}{../LRM/tests/bin/pass/badDim_dotprod_fail_r.log}

\loadsrc{range\_inv\_row\_fail\_r.mpx}{../LRM/tests/mpx/range_inv_row_fail_r.mpx}
\loadsrc{range\_inv\_row\_fail\_r.cpp}{../LRM/tests/cpp/range_inv_row_fail_r.cpp}
\loadsrc{range\_inv\_row\_fail\_r.log}{../LRM/tests/bin/pass/range_inv_row_fail_r.log}

\loadsrc{range\_inv\_col\_fail\_r.mpx}{../LRM/tests/mpx/range_inv_col_fail_r.mpx}
\loadsrc{range\_inv\_col\_fail\_r.cpp}{../LRM/tests/cpp/range_inv_col_fail_r.cpp}
\loadsrc{range\_inv\_col\_fail\_r.log}{../LRM/tests/bin/pass/range_inv_col_fail_r.log}

\loadsrc{range\_oob\_col\_fail\_r.mpx}{../LRM/tests/mpx/range_oob_col_fail_r.mpx}
\loadsrc{range\_oob\_col\_fail\_r.cpp}{../LRM/tests/cpp/range_oob_col_fail_r.cpp}
\loadsrc{range\_oob\_col\_fail\_r.log}{../LRM/tests/bin/pass/range_oob_col_fail_r.log}

\loadsrc{range\_oob\_row\_fail\_r.mpx}{../LRM/tests/mpx/range_oob_row_fail_r.mpx}
\loadsrc{range\_oob\_row\_fail\_r.cpp}{../LRM/tests/cpp/range_oob_row_fail_r.cpp}
\loadsrc{range\_oob\_row\_fail\_r.log}{../LRM/tests/bin/pass/range_oob_row_fail_r.log}

\loadsrc{range\_neg\_fail\_r.mpx}{../LRM/tests/mpx/range_neg_fail_r.mpx}
\loadsrc{range\_neg\_fail\_r.cpp}{../LRM/tests/cpp/range_neg_fail_r.cpp}
\loadsrc{range\_neg\_fail\_r.log}{../LRM/tests/bin/pass/range_neg_fail_r.log}

\section{Performance Tests}
\loadsrc{Timing Test Script}{../LRM/tests/timing/run.py}

\end{document}